<template>
  <div id="qrcode" style="text-align: center">
    <img style="width: 53%;margin-top: 80px" :src="codeURl" alt="">
    <br/>
    <span style="margin-top: 20px;font-size: 12px;display: block">请使用微信扫码，点击调试链接开始调试</span>
  </div>



</template>

<script>
  export default {
    data: function () {
      return {
        codeURl: ''
      }
    },
    mounted:function() {
      $('#qrcode').animateCss('bounceInRight', function() {
        // Do somthing after animation
      });
    },
    created: function () {
      let that = this;
      let infoList = [];
      Vue.ws.onmessage = function (e) {
        let data =JSON.parse(e.data);
        if(data.code) {
          if(data.mpId === JSON.parse(localStorage.getItem('selectItem')).mpId) {
            localStorage.setItem('openId', data.openId);
            localStorage.setItem('code', data.code);
            infoList.push(data);
            localStorage.setItem('infoList', JSON.stringify(infoList));
            //拿openId来实时刷新menu
            that.axios.get('wx_gateway/debugging/v1/menus?mpId='+localStorage.getItem('mpId')+'&openId='+localStorage.getItem('openId')).then((res) =>{
              // Vue.museList = res.data.data.buttons;
              localStorage.setItem("museList",JSON.stringify(res.data.data.buttons));
              that.$router.push('/main');
            }).catch((err) =>{
              weui.topTips(err.response.data.errorMessage,{
                className: 'topTipsStype',
              })
            });
          } else {
            weui.topTips(`触发调试失败，请到"${JSON.parse(localStorage.getItem('selectItem')).mpName}"公众号点击链接触发调试`,{
              className: 'topTipsStype',
              // duration: 1000000
            })
          }

        }
      };
      this.codeURl = decodeURIComponent(location.search.substr(9))
    },
    methods: {
      select() {
        // window.location = '/main'
      }

    }
  }
</script>

<style>
</style>
